package com.kanshu.basictest.ui.activity.view.recyclerview;

import android.view.View;

import com.kanshu.basictest.R;
import com.kanshu.basictest.model.menu.MenuItem;
import com.kanshu.basictest.ui.base.BaseToolbarActivity;
import com.kanshu.basictest.widget.adapter.menu.RecyclerMenuAdapter;
import com.kanshu.basictest.widget.adapter.recycler.BasicLinearItemDecoration;
import com.kanshu.basictest.widget.adapter.recycler.CustomLayoutManager;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class LayoutManagerTestActivity extends BaseToolbarActivity implements RecyclerMenuAdapter.OnItemClickedListener<MenuItem> {
    @BindView(R.id.rv_menu)
    RecyclerView rvMenu;

    private static final String TAG = "LayoutManagerActivity";

    @Override
    protected int provideLayoutResId() {
        return R.layout.activity_recycler_view;
    }


    @Override
    protected String provideBarTitle() {
        return "LayoutManager 测试";
    }


    @Override
    protected void init() {
        super.init();
        initRecyclerView();

    }

    private void initRecyclerView() {
        List<MenuItem> menuItems = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            menuItems.add(i, new MenuItem("项目" + i, R.color.gray_500));
        }
        RecyclerMenuAdapter<MenuItem> listMenuAdapter = new RecyclerMenuAdapter<>(menuItems);
        listMenuAdapter.setOnItemClickedListener(this);
       /* RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
        rvMenu.setLayoutManager(layoutManager);*/


        CustomLayoutManager customLayoutManager = new CustomLayoutManager();
        rvMenu.setLayoutManager(customLayoutManager);

        //基本的分割线
        rvMenu.addItemDecoration(new BasicLinearItemDecoration());
        rvMenu.setAdapter(listMenuAdapter);
    }


    @Override
    public void onItemClicked(RecyclerView.Adapter<?> adapter, View itemView, MenuItem item, int pos) {
        showToast(item.getName());
    }
}
